package com.zang.exception;

import com.zang.constant.ResultCode;
import lombok.Getter;

/**
 * @author Zhang Qiang
 * @date 2019/10/24 16:34
 */
public class InnerException extends RuntimeException {
    private static final long serialVersionUID = 8779399925940682979L;

    /**\
     * 内部异常代码(内部记录日志的异常代码)
     */
    @Getter
    private ResultCode code;

    /**
     * 外部异常代码(抛客户端的错误代码)
     */
    @Getter
    private ResultCode outerCode;

    /**
     * 外部消息(抛客户端的错误或提示消息)
     */
    @Getter
    private String clientMsg;

    /**
     *
     * @param code 错误代码
     * @param msg 错误描述
     */
    public InnerException(ResultCode code, String  msg){
        super(msg);
        this.code = code;
    }

    /**
     * 创建异常
     * @param code 内部错误代码
     * @param msg 内部错误描述
     * @param clientCode 客户端错误代码
     * @param clientMsg 客户端错误消息
     */
    public InnerException(ResultCode code, String msg, ResultCode clientCode, String clientMsg){
        super(msg);
        this.code = code;
        this.outerCode = clientCode;
        this.clientMsg = clientMsg;
    }

    /**
     * 字符串转化
     * @return 错误消息字符串
     */
    @Override
    public String toString(){
        return "RuntimeException(Code:"+this.code +";Message:"+super.getLocalizedMessage()+")";
    }
}
